#!/bin/bash

# Function to convert camelCase to spinal-case
convert_to_spinal() {
    echo "$1" | sed -r 's/([a-z0-9])([A-Z])/\1-\2/g' | tr '[:upper:]' '[:lower:]'
}

# Rename directories first (bottom-up to avoid path issues)
find src -type d -name "*[A-Z]*" | sort -r | while read dir; do
    dirname=$(basename "$dir")
    newname=$(convert_to_spinal "$dirname")
    if [ "$dirname" != "$newname" ]; then
        parent=$(dirname "$dir")
        echo "Renaming directory: $dir -> $parent/$newname"
        mv "$dir" "$parent/$newname"
    fi
done

# Rename files
find src -type f -name "*[A-Z]*" | while read file; do
    filename=$(basename "$file")
    newname=$(convert_to_spinal "$filename")
    if [ "$filename" != "$newname" ]; then
        dir=$(dirname "$file")
        echo "Renaming file: $file -> $dir/$newname"
        mv "$file" "$dir/$newname"
    fi
done